package com.llkj.qingnianguoxue.adapter;

import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.llkj.qingnianguoxue.R;
import com.llkj.qingnianguoxue.bean.ContributionsBean;
import com.llkj.qingnianguoxue.util.DateUtils;
import com.llkj.qingnianguoxue.util.ImageLoadingUtil;

import java.util.List;

/**
 * 缴费明细适配器
 */
public class ContributionsListAdapter extends BaseQuickAdapter<ContributionsBean, BaseViewHolder> {

    public ContributionsListAdapter(int layoutResId, List<ContributionsBean> data) {
        super(layoutResId, data);
    }

    @Override
    protected void convert(BaseViewHolder baseViewHolder, ContributionsBean item) {
        ImageLoadingUtil.loadingCircleBorderImg((ImageView) baseViewHolder.getView(R.id.iv_head),
                item.getUserpic(), R.color.transparent);
        baseViewHolder.setText(R.id.tv_name,item.getUsername());
        baseViewHolder.setText(R.id.tv_time, item.getAddtime());
        baseViewHolder.setText(R.id.tv_money, "+"+item.getCircle_price()+"银子");

        baseViewHolder.setText(R.id.tv_date,item.getDate());
        TextView tvDate = baseViewHolder.getView(R.id.tv_date);
        View lineBottom = baseViewHolder.getView(R.id.line_bottom);
        int currentPosition = baseViewHolder.getLayoutPosition();

        if(currentPosition> 0 && item.getDate().equals(mData.get(currentPosition-1).getDate())){//第一个位置，或者当前位置和上一个日期相同
            tvDate.setVisibility(View.GONE);
        }else{
            tvDate.setVisibility(View.VISIBLE);
        }

        //最后一个和下一个item和当前日期不同，显示底部line
        if(currentPosition == mData.size()-1 ||
                (currentPosition+1<mData.size() && item.getDate().equals(mData.get(currentPosition+1).getDate()))){
            lineBottom.setVisibility(View.VISIBLE);
        }else{
            lineBottom.setVisibility(View.GONE);
        }

    }

}
